#!/usr/bin/python
# -*- coding: UTF-8 -*- 
#记得先要安装pymysql组件，
import pymysql
#定义数据实体类


def mysqlData():
    jsonData = []
    connect = pymysql.Connect(
        host='localhost',
        port=3306,
        user='root',
        passwd='password',
        db='rcl',
        charset='utf8'
    )

    # 获取游标
    cursor = connect.cursor()
       
    # SQL 插入语句，INSERT INTO `svnlog` (`staff`, `dt`, `repo`, `file`, `path`, `amd`) VALUES ('zhouxj', '2222', '222', '333', '4444', '555')
    sql = "select CUSTOMERID,FULLNAME,BIRTHDAY from ind_info;"
    try:
        # 执行sql语句
        resultq =cursor.execute(sql)
        
        for row in cursor:  
            print(row[0],"    ", row[1],"    ",row[2],"    ")  
            result = {} 
            result['cu'] = row[0]  
            result['fn'] = row[1]  
            result['brd'] = row[2]  
       
            jsonData.append(result)
        # 执行sql语句
        connect.commit()
        print(jsonData)
        print("成功！")
    except Exception as e:
        print(e)
        # 发生错误时回滚
        connect.rollback()
        print("错误！")
    cursor.close()
    connect.close()
    return jsonData


mysqlData()
